package com.e3.web.core.client;

/**
 * 实现 GWT.Window 没有实现的一些功能。
 * 
 * @author aibo zeng
 */

public class WindowEx {
	
	public static native void refreshWindow()/*-{
		$wnd.location.reload();
	}-*/;
	
	public static native void link(String href, String parameterAndValue)/*-{
		$wnd.location = href+ '?'+ parameterAndValue;
	}-*/;
	
	public static native void forward(String url)/*-{
		$wnd.location = url;
	}-*/;
	
	public static native void forwardParentParent(String url)/*-{
	$wnd.parent.parent.location = url;
	}-*/;
	
	/**
	 * String url = GWT.getModuleBaseURL() + "FrameWork.jsp?modulCode=101&gwtParam1=voId";
	 * 
	 * @param url
	 */
	public static native void openWindow(String url)/*-{
	    $wnd.open(url);
    }-*/;
	
	public static native void forwardParent(String url)/*-{
		$wnd.parent.location = url;
	}-*/;
	
	/**
	 * Creates a modal dialog box that displays the specified HTML document.
	 * 
	 * @param url
	 *            -Required. String that specifies the URL of the document to load and display.
	 * @param args
	 *            -Optional. Variant that specifies the arguments to use when displaying the document. Use this parameter to pass a value of any type,
	 *            including an array of values. The dialog box can extract the values passed by the caller from the dialogArguments property of the
	 *            window object.
	 * @param features
	 *            -
	 * 
	 *            <pre>
	 * Optional. String that specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values: dialogHeight:sHeight Sets the height of the dialog window (see Remarks for default unit of measure). 
	 * dialogLeft:sXPos Sets the left position of the dialog window relative to the upper-left corner of the desktop. 
	 * dialogTop:sYPos Sets the top position of the dialog window relative to the upper-left corner of the desktop. 
	 * dialogWidth:sWidth Sets the width of the dialog window (see Remarks for default unit of measure). 
	 * center:{ yes | no | 1 | 0 | on | off } Specifies whether to center the dialog window within the desktop. The default is yes. 
	 * dialogHide:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window is hidden when printing or using print preview. This feature is only available when a dialog box is opened from a trusted application. The default is no. 
	 * edge:{ sunken | raised } Specifies the edge style of the dialog window. The default is raised. 
	 * help:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays the context-sensitive Help icon. The default is yes. 
	 * resizable:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window has fixed dimensions. The default is no. 
	 * scroll:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays scrollbars. The default is yes. 
	 * status:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays a status bar. The default is yes for untrusted dialog windows and no for trusted dialog windows. 
	 * unadorned:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays the border window chrome. This feature is only available when a dialog box is opened from a trusted application. The default is no.
	 * 
	 * 
	 * 
	 * </pre>
	 */
	public static native void showModalDialog(String url, String args, String features)/*-{
		$wnd.showModalDialog(url, args, features);
	}-*/;
	
	/**
	 * 使用正则表达式判断用户录入是否在约定的模式之下 IE和遨游下测试通过
	 * 
	 * @param pattren
	 *            如：AAA-[0-9]{5,5} 只能录入 AAA-后面带5位的数字
	 * @param target
	 *            用户录入的要比较的
	 * @return true or false
	 * @see http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html 注意：参数都是空格“”，matches返回 true
	 */
	public static boolean validateByPattern(String pattern, String target) {
		if (pattern == null || pattern.length() <= 0) {
			// 不做判断
			return true;
		}
		if (target == null) {
			target = "";
		}
		return target.matches(pattern);
	}
	
	/**
	 * 读取：主页里的JavaScript变量. 主页里的JavaScript必须提供一个 function getParameterByName() 注意：返回值暂时固定是 String 使用例子： String voId =
	 * WindowEx.getStringParameterByName("gwtParam1");
	 * 
	 * @param name
	 * @return
	 */
	public static native String getStringParameterByName(String name)/*-{
        return $wnd.getParameterByName(name);
    }-*/;
	
	public static native void close()/*-{
		$wnd.open('','_self','')
        $wnd.close();
    }-*/;
	
}
